# class for vector operations
from myvector import *

# constants needed internally
E_0 = 1.
R = 1.
eps_i = 1.2

# This title HAS TO BE DEFINED for the plot
plot_title = "Vektorfeld eps_i = %.2f, E_0 = %.2f, R = %.2f, z=0" % (eps_i, E_0, R)

def vectorfield(v):
	"""The function vectorfield receives a position vector, for which the field has
	to be computed, it returns a vector. It is called by the main program."""

	# here we just define a condition
	if v.r <= R:	return E_inner(v)
	else:			return E_outer(v)

######################### functions for internal use ###########################
def E_inner(v):
	"""Compute the inner field"""
	if not v.is_null():
		return vector( - E_0 / (eps_i + 2.), 0., 0.)
	else: return vector(0.,0.,0.)

def E_outer(v):
	"""Compute the inner field"""
	if not v.is_null():
		vor = R**3 / (v.r**5) * ( 1. / (eps_i + 2.) - 1.) * E_0

		return vector( vor * (3.* v.x**2 -v.r**2) + E_0, vor * 3 * v.x * v.y , vor * 3 * v.x * v.z)
	else:	return vector(0.,0.,0.)
